<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>06-渲染学生信息表</title>
    <style>
      table {
        border-collapse: collapse;
      }
      caption {
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 10px;
      }
      table,
      th,
      td {
        border: 1px solid black;
      }
      tr th {
        width: 140px;
        height: 32px;
        line-height: 32px;
        text-align: center;
        /* font-size: 14px;
        font-weight: 600; */
        background-color: #dddddd;
      }
      tr td {
        text-align: center;
        height: 32px;
        line-height: 32px;
        font-size: 14px;
        font-weight: 500;
      }
      table tr:nth-child(1) {
        background-color: #ddd;
      }
      tr:not(:first-child):hover {
        background-color: #eee;
      }
    </style>
  </head>

  <body>
    <h3>学生信息</h3>
    <h5>将数据渲染到页面中</h5>
    <table>
      <caption>
        学生列表
      </caption>
      <tr>
        <th>序号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>家乡</th>
      </tr>
      <!-- script 写到这里 -->
      <script>
        //1. 数据准备
        let students = [
          { name: '小明', age: 18, gender: '男', hometown: '湖北省' },
          { name: '小红', age: 22, gender: '女', hometown: '广西省' },
          { name: '小张', age: 25, gender: '女', hometown: '湖南省' },
          { name: '小李', age: 28, gender: '男', hometown: '广东省' },
        ]
        // 2.渲染页面
        for (let i = 0; i < students.length; i++) {
          document.write(`
              <tr>
                <td>${i + 1}</td>
                <td>${students[i].name}</td>
                <td>${students[i].age}</td>
                <td>${students[i].gender}</td>
                <td>${students[i].hometown}</td>
            </tr>
          `)
        }
      </script>
    </table>
  </body>
</html>
